<?php

/**
 * Not used.... here for reference..
 *
 */
class View_Helper_HESTLink extends Zend_View_Helper_Abstract
{
    protected static $_acl = null;
    protected static $_request = null;
    protected static $_router = null;
    
    public function __construct()
    {
        if (self::$_acl === null) {
            $registry = Zend_Registry::getInstance();
            if (!$registry->isRegistered('acl')) {
                throw new Exception('Acl is not in registry under key: \'acl\'');
            }
            self::$_acl = Zend_Registry::getInstance()->acl;
            if (!self::$_acl || !is_callable(array(self::$_acl, 'isUserAllowed'))) {
                throw new Exception('Acl is null, or does not implement isUserAllowed');
            }
        }
        
        self::$_request = Zend_Controller_Front::getInstance()->getRequest();
        self::$_router = Zend_Controller_Front::getInstance()->getRouter();
    }
    
    
    function link($title, array $url = array(), array $options = array())
    {        
        if (isset($options['style'])) {
            $target = 'target=\"' . $options['target'] . '\"';
            unset($options['target']);
        }
        
        if (!isset($url['module'])) {
            $url['module'] = self::$_request->getModuleName();
        }
        if (!isset($url['controller'])) {
            $url['controller'] = self::$_request->getControllerName();
        }
        if (!isset($url['action'])) {
            $url['action'] = self::$_request->getActionName();
        }
        
        if (!self::$_acl->isUserAllowed($url['module'], $url['controller'], $url['action'])) {
            return '';
        }
        
        $target = '';
        if (isset($options['target'])) {
            $target = ' target="' . $options['target'] . '"';
        }
        
        $class = '';
        if (isset($options['class'])) {
            $target = ' class="' . $options['class'] . '"';
        }
        
        $url = self::$_router->assemble($url, null, true, true);
        $html = '<a href="' . $url . '"' . $target . $class . '>' . $this->view->escape($title) . '</a>';
        
        return $html;
    }
}
